home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-11-27 | 9.5 KB | 409 lines | [TEXT/CWIE] |
- // ---------------------------------------------------------------------------
- // CDirectoryTable.cp
- // written by Rick Eames
- // (c) 1996 Rick Eames. All Rights Reserved.
- //
- // If I were really smart, I'd turn this into something abstract and allow
- // overriding of key methods. But I'm not that smart. ;-)
- //
- // ---------------------------------------------------------------------------
-
- #include "CDirectoryTable.h"
-
- #include <LTableMonoGeometry.h>
- #include <LTableMultiGeometry.h>
- #include <LTableSingleSelector.h>
- #include <LTableMultiSelector.h>
- #include <LTableArrayStorage.h>
- #include <UAttachments.h>
- #include <UCollapsableTree.h>
- #include <UDrawingUtils.h>
- #include <UTextTraits.h>
-
-
- // ---------------------------------------------------------------------------
- // ---------------------------------------------------------------------------
-
- const long size_NameWidth = 200;
- const long size_UnreadWidth = 50;
- const long size_TotalWidth = 50;
- const long size_CellHeight = 20;
- const long kTextIndent = 22;
- const long kTextBottom = 2;
- const ResIDT icon_Folder = 15000;
- const ResIDT icon_Mail = 15001;
- const ResIDT icon_NewMail = 15002;
-
- // ---------------------------------------------------------------------------
- // ---------------------------------------------------------------------------
-
- CDirectoryTable*
- CDirectoryTable::CreateFromStream(
- LStream *inStream)
- {
- return (new CDirectoryTable(inStream));
- }
-
- // ---------------------------------------------------------------------------
- // ---------------------------------------------------------------------------
-
- CDirectoryTable::CDirectoryTable(
- LStream *inStream)
- : LHierarchyTable(inStream)
- {
- mTableGeometry = new LTableMultiGeometry(this, size_TotalWidth, size_CellHeight);
- mTableSelector = new LTableMultiSelector(this);
- mTableStorage = new LTableArrayStorage(this, sizeof(FSSpec));
-
- InsertCols(1, 0, nil, nil, false);
- mTableGeometry->SetColWidth(size_NameWidth, 1, 1);
- // mTableGeometry->SetColWidth(size_UnreadWidth, 2, 2);
- // mTableGeometry->SetColWidth(size_TotalWidth, 3, 3);
-
- mCurrentRow = 0;
-
- mLastDragCell.row = mLastDragCell.col =-1;
-
- LEraseAttachment* theAttachment;
- theAttachment = new LEraseAttachment();
- if (theAttachment)
- AddAttachment(theAttachment, nil, true);
- }
-
- #pragma mark -
-
- // ---------------------------------------------------------------------------
- // ---------------------------------------------------------------------------
-
- void
- CDirectoryTable::AddFile(
- FSSpec &inFile,
- Int32 inParentRow,
- Int32 /* inRow */,
- Int32 inSiblingRow)
- {
- if (inParentRow == 0)
- {
- InsertSiblingRows(1, inSiblingRow,&inFile, sizeof(FSSpec), false, true);
- }
- else
- {
- InsertChildRows(1, inParentRow, &inFile, sizeof(FSSpec), false, true);
- }
-
- Refresh();
- }
-
- // ---------------------------------------------------------------------------
- // ---------------------------------------------------------------------------
-
- void
- CDirectoryTable::AddFolder(
- FSSpec &inFolder,
- Int32 inParentRow,
- Int32 /* inRow */,
- Int32 inSiblingRow)
- {
- if (inParentRow == 0)
- {
- InsertSiblingRows(1, inSiblingRow,&inFolder, sizeof(FSSpec), true, true);
- }
- else
- {
- InsertChildRows(1, inParentRow, &inFolder, sizeof(FSSpec), true, true);
- }
-
- Refresh();
- }
-
- // ---------------------------------------------------------------------------
- // ---------------------------------------------------------------------------
-
- void
- CDirectoryTable::BuildList(
- FSSpec &inDirectory,
- Int32 parentRow)
- {
- CInfoPBRec cipbr;
- HFileInfo *fpb = (HFileInfo*) &cipbr;
- DirInfo *dpb = (DirInfo*) &cipbr;
- short rc, index;
- FSSpec foundSpec;
- Int32 dirID;
- Int32 lastSiblingRow = 0;
-
- dirID = GetDirectoryID(inDirectory);
-
- fpb->ioVRefNum = inDirectory.vRefNum;
- fpb->ioNamePtr = foundSpec.name;
-
- foundSpec.vRefNum = inDirectory.vRefNum;
- foundSpec.parID = dirID;
-
- for (index = 1; true; index++)
- {
- fpb->ioDirID = dirID;
- fpb->ioFDirIndex = index;
-
- rc = PBGetCatInfoSync(&cipbr);
- if (rc) break;
-
- mCurrentRow++; // this should be the wide open index
-
- if (fpb->ioFlAttrib & 16)
- {
- AddFolder(foundSpec, parentRow, mCurrentRow, lastSiblingRow);
- lastSiblingRow = mCurrentRow;
- BuildList(foundSpec, mCurrentRow);
- }
- else
- {
- // if (fpb->ioFlFndrInfo.fdType == 'MBOX')
- // {
- AddFile(foundSpec, parentRow, mCurrentRow, lastSiblingRow);
- lastSiblingRow = mCurrentRow;
- // }
- }
- }
- }
-
- // ---------------------------------------------------------------------------
- // ---------------------------------------------------------------------------
-
- Int32
- CDirectoryTable::GetDirectoryID(
- FSSpec &inDirectory)
- {
- DirInfo pb;
-
- pb.ioCompletion = nil;
- pb.ioNamePtr = inDirectory.name;
- pb.ioVRefNum = inDirectory.vRefNum;
- pb.ioDrDirID = inDirectory.parID;
- pb.ioFDirIndex = 0;
-
- Int16 err = ::PBGetCatInfoSync((CInfoPBRec*)&pb);
-
- return pb.ioDrDirID;
- }
-
- #pragma mark -
-
- // ---------------------------------------------------------------------------
- // ---------------------------------------------------------------------------
-
- void
- CDirectoryTable::DrawCell(
- const STableCell &inCell,
- const Rect &inLocalRect)
- {
- TableIndexT woRow = mCollapsableTree->GetWideOpenIndex(inCell.row);
- Uint32 nestingLevel = mCollapsableTree->GetNestingLevel(woRow);
- STableCell actualCell;
-
- actualCell = inCell;
- actualCell.row = woRow;
-
- // get the data
- FSSpec theFile;
- Uint32 theFileSize = sizeof(FSSpec);
-
- GetCellData(actualCell, &theFile, theFileSize);
-
- if (mCollapsableTree->IsCollapsable(woRow))
- {
- switch (inCell.col)
- {
- case 1:
- DrawDropFlag(inCell, woRow);
- UTextTraits::SetPortTextTraits(200);
-
- Rect r;
- r = inLocalRect;
- r.left += (kTextIndent * (nestingLevel+1));
- r.right = r.left + 16;
- r.bottom = r.top + 16;
-
- ::PlotIconID(&r, atNone, ttNone, icon_Folder);
-
- r.top += 4;
- r.bottom += 4;
- r.left = r.right + 5;
- r.right = inLocalRect.right;
-
- UTextDrawing::DrawWithJustification((char*)&theFile.name[1], theFile.name[0], r, teJustLeft);
- break;
-
- case 2:
- {
- UTextTraits::SetPortTextTraits(200);
- Rect r = inLocalRect;
- r.top += 4;
- UTextDrawing::DrawWithJustification("-", 1, r, teJustCenter);
- break;
- }
-
- case 3:
- {
- UTextTraits::SetPortTextTraits(200);
- Rect r = inLocalRect;
- r.top += 4;
- UTextDrawing::DrawWithJustification("-", 1, r, teJustCenter);
- break;
- }
- }
- }
- else
- {
- UTextTraits::SetPortTextTraits(201);
-
- switch (inCell.col)
- {
- case 1:
- {
- Rect r;
- r = inLocalRect;
- r.left += (kTextIndent * (nestingLevel+1));
- r.right = r.left + 16;
- r.bottom = r.top + 16;
-
- ::PlotIconID(&r, atNone, ttNone, icon_Mail);
-
- r.left = r.right + 5;
- r.right = inLocalRect.right;
- r.top += 4;
- r.bottom += 4;
-
- UTextDrawing::DrawWithJustification((char*)&theFile.name[1], theFile.name[0], r, teJustLeft);
-
- break;
- }
-
- case 2:
- {
- Rect r = inLocalRect;
- r.top += 4;
- UTextDrawing::DrawWithJustification("123", 3, r, teJustCenter);
- break;
- }
-
- case 3:
- {
- Rect r = inLocalRect;
- r.top += 4;
- UTextDrawing::DrawWithJustification("500", 3, r, teJustCenter);
- break;
- }
- }
- }
- }
-
- // ---------------------------------------------------------------------------
- // ---------------------------------------------------------------------------
-
- void
- CDirectoryTable::ClickCell(
- const STableCell& inCell,
- const SMouseDownEvent& inMouseDown)
- {
- #pragma unused (inMouseDown)
- if (sClickCount < 2)
- {
- // if (::WaitMouseMoved(inMouseDown.macEvent.where))
- // {
- // CreateDragEvent(inCell, inMouseDown);
- // }
- }
- else
- {
- TableIndexT woRow = mCollapsableTree->GetWideOpenIndex(inCell.row);
- Uint32 nestingLevel = mCollapsableTree->GetNestingLevel(woRow);
- STableCell actualCell;
-
- actualCell = inCell;
- actualCell.row = woRow;
-
- // get the data
- FSSpec theFile;
- Uint32 theFileSize = sizeof(FSSpec);
-
- GetCellData(actualCell, &theFile, theFileSize);
-
- BroadcastMessage('CLIK', &theFile);
- }
- }
-
- #pragma mark -
-
- // ---------------------------------------------------------------------------
- // • HiliteCellActively
- // ---------------------------------------------------------------------------
- // Draw or undraw active hiliting for a Cell
-
- void
- CDirectoryTable::HiliteCellActively(
- const STableCell &inCell,
- Boolean inHilite)
- {
- #if 0
- Rect cellFrame;
- STableCell firstCell = inCell;
-
- TableIndexT woRow = mCollapsableTree->GetWideOpenIndex(inCell.row);
-
- firstCell.col = 1;
-
- if (mCollapsableTree->IsCollapsable(woRow)) return;
-
- if (GetLocalCellRect(firstCell, cellFrame) && FocusExposed())
- {
- UDrawingUtils::SetHiliteModeOn();
- ::InvertRect(&cellFrame);
- }
- #else
- #pragma unused (inCell, inHilite)
- #endif
- }
-
- // ---------------------------------------------------------------------------
- // ---------------------------------------------------------------------------
-
- void
- CDirectoryTable::HiliteCellInactively(
- const STableCell &inCell,
- Boolean inHilite)
- {
- #if 0
- #pragma unused (inHilite)
-
- Rect cellFrame;
-
- TableIndexT woRow = mCollapsableTree->GetWideOpenIndex(inCell.row);
-
- if (mCollapsableTree->IsCollapsable(woRow)) return;
-
- if (GetLocalCellRect(inCell, cellFrame) && FocusExposed())
- {
- UDrawingUtils::SetHiliteModeOn();
- ::PenNormal();
- ::PenMode(srcXor);
- ::FrameRect(&cellFrame);
- }
- #else
- #pragma unused (inCell, inHilite)
- #endif
- }
-
- // ---------------------------------------------------------------------------
- // ---------------------------------------------------------------------------
-
- void
- CDirectoryTable::HiliteSelection(
- Boolean isActively,
- Boolean inHilite)
- {
- #pragma unused (isActively, inHilite)
- // do nothing
- }
-
-